<template>
	<view class="mine">
		<view class="bg">
			<image style="width: 100%;" :src="baseImgUrl+'mine/bg.png'" mode=""></image>
		</view>
		<view class="mine-bg">
			<nav-bar :showLeftIcon="false" :leftSlot="false" style="background: transparent;"></nav-bar>
			<view class="user">
				<view class="user-info">
					<image :src="baseImgUrl + 'headerDefault.png'" mode="widthFix"></image>
					<view class="user-info-details" v-if="wbMasterEnter && wbMasterEnter.auditStatus == 1">
						<text>{{wbMasterEnter.name}}</text>
						<text>
							<!-- <text>{{wbMasterEnter.phoneNumber}}</text> -->
							<!-- <text style="margin-left: 20rpx;">用户角色</text> -->
						</text>
					</view>
					<view class="user-info-details" v-else-if="wbEntAuthList && wbEntAuthList.state == 1">
						<text>{{userInfo.nickName}}</text>
						<text>
							<!-- <text>{{wbEntAuthList.phoneNumber}}</text> -->
							<!-- <text style="margin-left: 20rpx;">用户角色</text> -->
						</text>
					</view>
					<view class="user-info-details" v-else>
						<text>{{userInfo.nickName}}</text>
						<text>
							<!-- <text>{{userInfo.phoneNumber}}</text> -->
							<!-- <text style="margin-left: 20rpx;">普通用户</text> -->
						</text>
					</view>
				</view>
				<view class="authentication" @click="toEnterCertification" v-if="wbEntAuthList.state">
					<image :src="baseImgUrl + 'mine/renzhen_icon.png'" mode="widthFix"></image>
					<text v-if="wbEntAuthList.state == 1">已认证</text>
					<text v-else-if="wbEntAuthList.state == 2">认证中</text>
					<text v-else>企业认证</text>
				</view>
			</view>
			<view class="company" v-if="wbEntAuthList && wbEntAuthList.state">
				<text>{{wbEntAuthList.entName}}</text>
				<image v-if="wbEntAuthList.state == 1" :src="baseImgUrl + 'mine/authentication.png'" mode="widthFix">
				</image>
			</view>
			<view class="firm-info">
				<view class="firm-title">
					<text>企业信息</text>
					<view>
						<!-- <text>全部</text>
						<image :src="baseImgUrl + 'home/more.png'" mode="widthFix"></image> -->
					</view>
				</view>
				<view class="firm-box">
					<view class="firm-item" v-for="(item,index) in firm" :key="index" @click="toFirmPage(item)">
						<image :src="item.img" mode="widthFix"></image>
						<text>{{item.text}}</text>
					</view>
				</view>
			</view>
			<view class="moreOptions" :style="{height: scrollHeight}">
				<view class="moreOptions-box">
					<view class="moreOptions-item" v-for="(item,index) in moreOptions" :key="index"
						@click="moreOptionsFun(item)">
						<view>
							<image :src="item.img" mode="widthFix"></image>
							<text>{{item.text}}</text>
						</view>
						<image :src="baseImgUrl + 'home/message_arrow.png'" mode="widthFix"></image>
					</view>
				</view>
				<view class="quit" @click="logoutMe">
					退出登录
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Common from '@/api/common.js'
	import pageConfig from '@/config'
	const baseUrl = pageConfig.baseUrl,
		baseImgUrl = pageConfig.baseImgUrl;
	import Login from '@/api/login.js'
	import {
		removeToken
	} from '@/utils/auth.js'
	export default {
		data() {
			return {
				baseImgUrl,
				scrollHeight: '',
				firm: [{
						img: baseImgUrl + 'mine/maintenanceRecord.png',
						text: '维保记录',
						url: '/subPages/home/maintenanceRecordsCheck', //subPages/mine/maintenanceRecords
					},
					{
						img: baseImgUrl + 'mine/personnelRtructure.png',
						text: '人员架构',
						url: '/subPages/mine/personnelRtructure',
					},
					{
						img: baseImgUrl + 'mine/electricalSafety.png',
						text: '用电安全',
						url: '/subPages/mine/electricalSafety/records',
					},
					{
						img: baseImgUrl + 'mine/escapeRoute.png',
						text: '疏散通道',
						url: '/subPages/mine/escapeRoute/records',
					},
				],
				moreOptions: [{
						img: baseImgUrl + 'mine/cooperator.png',
						text: '合作单位',
						url: '/subPages/mine/cooperativeUnits',
					},
					// {
					// 	img: baseImgUrl + 'mine/reportDownload.png',
					// 	text: '报告下载',
					// 	url: '',
					// },

					{
						img: baseImgUrl + 'mine/serviceContract.png',
						text: '服务协议',
						url: '/subPages/mine/serviceAgreement',
					},
					{
						img: baseImgUrl + 'mine/reportDownload.png',
						text: '投诉建议',
						url: '/subPages/mine/complaint',
					},
					{
						img: baseImgUrl + 'mine/about.png',
						text: '关于我们',
						url: '/subPages/mine/about',
					},
				],
				// 是否企业认证
				isEnterCertification: false,
				// 企业信息
				wbEntAuthList: {},
				// 师傅信息
				wbMasterEnter: {},
				// 用户信息
				userInfo: {},
				//维保公司信息
				maintainCompany: {},
			}
		},
		onLoad() {
			this.scrollHeight = this.$store.getters.heightData.noTabMainHeight - 337 + 'px';
		},
		onShow() {
			// 获取当前用户角色
			this.getUserInfo();
		},
		methods: {
			async getUserInfo() {
				let res = await Common.getInfo();
				this.wbMasterEnter = res.wbMasterEnter;
				this.wbEntAuthList = res.wbEntAuth;
				this.userInfo = res.user;
				this.maintainCompany=res.maintainCompany
				if (res.ifDownload && res.ifDownload.length != 0) {
					uni.showToast({
						title: '您还有未下载文件，请前往维保记录下载',
						icon: 'none'
					});
				}
			},
			moreOptionsFun(item) {
				if (item.text == '投诉建议') {
					let url = item.url + '?username=' + this.userInfo.nickName
					this.navigator(url)
				} else {
					this.navigator(item.url)
				}
			},
			navigator(url) {
				uni.navigateTo({
					url
				})
			},
			toEnterCertification() {
				if (this.wbMasterEnter && JSON.stringify(this.wbMasterEnter) != '{}') {
					uni.showToast({
						icon: 'none',
						title: '您已申请师傅入驻，不能再进行企业认证'
					})
					return;
				} else {
					if (this.wbEntAuthList && this.wbEntAuthList.state) {
						if (this.wbEntAuthList.state == 2) {
							uni.navigateTo({
								url: '/subPages/home/master/notExamine?title=企业认证&msg=请您耐心等待'
							})
							return;
						}
					}
				}
				uni.navigateTo({
					url: '/subPages/mine/enterCertification'
				})
			},
			toFirmPage(item) {
				let url = item.url;
				console.log(this.wbEntAuthList, 'this.wbEntAuthList');
				if (this.wbEntAuthList == null || this.wbEntAuthList.state != 1) {
					if (url.includes('maintenanceRecordsCheck')) {
						this.navigator(url);
					} else {
						uni.showToast({
							icon: 'none',
							title: '您还还没有企业认证，请先进行认证'
						})
						return;
					}
				} else {
					url = url + '?entId=' + this.wbEntAuthList.id + '&entName=' + this.wbEntAuthList.entName +
						'&maintainCompanyId=' + this.maintainCompany.id
						console.log(url, 'url');
					this.navigator(url);
				}


				// this.navigator(url);
			},
			logoutMe() {
				Login.logout().then(res => {
					removeToken();
					uni.switchTab({
						url: '/pages/home'
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.mine {
		background-color: #F6F8FA;
		height: 100vh;
		background-size: 100%;
		background-repeat: no-repeat;
		display: flex;
		flex-direction: column;

		.bg {
			height: 445rpx;
			width: 100vw;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 0;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.mine-bg {
			cursor: pointer;
			padding: 0 30rpx;
			z-index: 2;

			.user {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 20rpx 0 40rpx;
				z-index: 2;

				.user-info {
					display: flex;
					align-items: stretch;

					image {
						width: 120rpx;
						height: 120rpx;
						background: #acacac;
						border-radius: 50%;
					}

					.user-info-details {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						padding: 10rpx 20rpx;

						>text {
							font-family: "PingFang SC";
							font-size: 24rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
							opacity: 0.5;
							margin-right: 20rpx;

							&:first-child {
								font-family: "PingFang SC";
								font-size: 36rpx;
								font-style: normal;
								font-weight: 550;
								line-height: normal;
								opacity: 1;

							}
						}
					}
				}

				.authentication {
					display: flex;
					align-items: center;
					padding: 9rpx 20rpx;
					border: 2rpx solid #325ef5;
					color: #325ef5;
					font-family: "PingFang SC";
					font-size: 24rpx;
					font-style: normal;
					font-weight: 400;
					line-height: normal;
					border-radius: 10rpx;

					image {
						width: 40rpx;
						height: 40rpx;
						margin-right: 20rpx;
					}
				}
			}

			.company {
				padding: 24rpx;
				margin: 0 30rpx;
				border-top-right-radius: 20rpx;
				border-top-left-radius: 20rpx;
				background: #4e86f9;
				position: relative;

				text {
					color: #ffffff;
					font-family: "PingFang SC";
					font-size: 28rpx;
					font-style: normal;
					font-weight: 500;
					line-height: 40rpx;
				}

				image {
					position: absolute;
					top: 0;
					right: 30rpx;
					width: 78rpx;
					height: 74rpx;
				}
			}

			.firm-info {
				padding: 30rpx;
				border-radius: 20rpx;
				background: #ffffff;
				margin-bottom: 20rpx;

				.firm-title {
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-family: "PingFang SC";
					font-size: 32rpx;
					font-style: normal;
					font-weight: 500;
					line-height: 40rpx;
					opacity: 0.9;
					margin-bottom: 40rpx;

					view {
						text {
							font-family: "PingFang SC";
							font-size: 26rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
							opacity: 0.5;
						}

						image {
							width: 16rpx;
							height: 20rpx;
							margin-left: 12rpx;
						}
					}
				}

				.firm-box {
					display: flex;
					justify-content: space-between;

					.firm-item {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;

						image {
							width: 80rpx;
							height: 80rpx;
							border-radius: 50%;
							margin-bottom: 10rpx;
						}
					}
				}
			}

			.moreOptions {
				padding: 10rpx 30rpx;
				border-radius: 20rpx;
				background: #ffffff;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				padding-bottom: 34rpx;

				.moreOptions-box {
					.moreOptions-item {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 30rpx 0;

						image {
							width: 42rpx;
							height: 42rpx;
						}

						view {
							display: flex;
							justify-content: space-between;
							align-items: center;

							text {
								font-family: "PingFang SC";
								font-size: 30rpx;
								font-style: normal;
								font-weight: 400;
								line-height: normal;
								opacity: 0.9;
								margin-left: 20rpx;
							}
						}
					}
				}

				.quit {
					margin: 0 155rpx;
					padding: 20rpx 0;
					border-radius: 20rpx;
					background: #325ef5;
					color: #ffffff;
					text-align: center;
					font-family: "PingFang SC";
					font-size: 30rpx;
					font-style: normal;
					font-weight: 400;
					line-height: normal;
				}
			}
		}
	}
</style>